package com.sen.paydemo.controller;


import com.sen.paydemo.service.PaymentInfoService;
import com.sen.paydemo.entity.PaymentInfo;
import com.sen.paydemo.param.PaymentInfoParam;

import com.sen.paydemo.vo.ApiResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 支付记录控制器
 *
 * @author 韩宗森
 * @since 2024-01-09 19:53:30
 */
@Tag(name = "支付记录管理")
@RestController
@RequestMapping("/api/paydemo/payment-info")
public class PaymentInfoController extends BaseController {
    @Resource
    private PaymentInfoService paymentInfoService;


    @Operation(summary = "分页查询支付记录")
    @GetMapping("/page")
    public ApiResult<List<PaymentInfo>> page(PaymentInfoParam param) {

        // 使用关联查询
        return success(paymentInfoService.list());
    }


    @Operation(summary = "查询全部支付记录")
    @GetMapping()
    public ApiResult<List<PaymentInfo>> list(PaymentInfoParam param) {

        return success(paymentInfoService.list());

    }


    @Operation(summary = "根据id查询支付记录")
    @GetMapping("/{id}")
    public ApiResult<PaymentInfo> get(@PathVariable("id") Integer id) {
        return success(paymentInfoService.getById(id));
        // 使用关联查询
        //return success(paymentInfoService.getByIdRel(id));
    }


    @Operation(summary = "添加支付记录")
    @PostMapping()
    public ApiResult<?> save(@RequestBody PaymentInfo paymentInfo) {
        if (paymentInfoService.save(paymentInfo)) {
            return success("添加成功");
        }
        return fail("添加失败");
    }


    @Operation(summary = "修改支付记录")
    @PutMapping()
    public ApiResult<?> update(@RequestBody PaymentInfo paymentInfo) {
        if (paymentInfoService.updateById(paymentInfo)) {
            return success("修改成功");
        }
        return fail("修改失败");
    }

    @Operation(summary = "删除支付记录")
    @DeleteMapping("/{id}")
    public ApiResult<?> remove(@PathVariable("id") Integer id) {
        if (paymentInfoService.removeById(id)) {
            return success("删除成功");
        }
        return fail("删除失败");
    }


    @Operation(summary = "批量添加支付记录")
    @PostMapping("/batch")
    public ApiResult<?> saveBatch(@RequestBody List<PaymentInfo> list) {
        if (paymentInfoService.saveBatch(list)) {
            return success("添加成功");
        }
        return fail("添加失败");
    }


    @Operation(summary = "批量删除支付记录")
    @DeleteMapping("/batch")
    public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
        if (paymentInfoService.removeByIds(ids)) {
            return success("删除成功");
        }
        return fail("删除失败");
    }

}
